vector<vector<int>> threeSum(vector<int>& nums) {
    sort(nums.begin(), nums.end());
    vector<vector<int>> vv;

    int i = 0;
    while (i < nums.size() - 1)
    {
        int left = i + 1;
        int right = nums.size() - 1;
        int fake_sum = -nums[i];
        while (left < right)
        {
            if (nums[left] + nums[right] > fake_sum)
            {
                do
                {
                    --right;
                } while (right > i && nums[right] == nums[right + 1]);
            }
            else if (nums[left] + nums[right] < fake_sum)
            {
                do
                {
                    ++left;
                } while (left < nums.size() && nums[left] == nums[left - 1]);
            }
            else
            {
                vector<int> tmp{ nums[i], nums[left], nums[right] };
                vv.push_back(tmp);
                do
                {
                    --right;
                } while (right > i && nums[right] == nums[right + 1]);

                do
                {
                    ++left;
                } while (left < nums.size() && nums[left] == nums[left - 1]);
            }

        }
        do
        {
            ++i;
        } while (i < nums.size() && nums[i] == nums[i - 1]);
    }
    return vv;
}